#!/bin/bash

function screenshot() {
	OUTDIR=/vagrant/output/screenshots/$SITENAME
	if [ ! -d $OUTDIR ]
	then
		mkdir -p $OUTDIR
	fi
	
	for page in $SITENAME/ $SITENAME/nl $SITENAME/fr
	do
		echo "Navigating firefox to $page"
		rm -rf $HOME/.mozilla/firefox/Cache	
		firefox --display=:$DISPLAY.0 -a firefox -remote "openURL(http://$page)" -P testing &
	
		echo "Sleep 20 seconds"
		sleep 20
	
		echo "Capture screenshot"
		STAMP=`date +%Y%m%d%H%m`
		LANG=${page#$SITENAME/}
		import  -display :$DISPLAY.0 -window root $OUTDIR/$SITENAME-homepage-$LANG-$STAMP.png
	done
}


if [ $# -eq 1 ]
then
	DISPLAY=9
	SITENAME=$1
	
	screenshot
else
	echo "Usage: site_shot.sh <fqdn_site>"
	exit -1
fi
